namespace LS.UGFUnits
{
    using Unity.VisualScripting;

    public sealed class CheckNetworkChannelExisted : NetworkUnit
    {
        [DoNotSerialize]
        public ControlOutput Existed { get; private set; }
        
        [DoNotSerialize]
        public ControlOutput NotExisted { get; private set; }
        
        [DoNotSerialize]
        [PortLabelHidden]
        public ValueInput Name { get; private set; }
        
        protected override void Definition()
        {
            base.Definition();
            Existed = ControlOutput(nameof(Existed));
            NotExisted = ControlOutput(nameof(NotExisted));
            Name =  ValueInput<string>(nameof(Name), string.Empty);
            Requirement(Name, Input);
        }

        protected override ControlOutput In(Flow flow)
        {
            string name = flow.GetValue<string>(Name);
            if (Target?.HasNetworkChannel(name) ?? false)
            {
                return Existed;
            }
            return NotExisted;
        }
    }
}